#include "Stdafx.h"
#include "DecalSystem.h"

namespace Pulpy
{
	void DecalSystem::draw(const Vector3D<float> &v)
	{
		glDisable(GL_CULL_FACE);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBindTexture(GL_TEXTURE_2D, _DecalSprites->getTexID());
		for(int i = 0; i < _CurrentIndex; i++)
		{	
			_DecalSprites->setIndex(_DecalList[i].getSpriteIndex());
			_DecalList[i].drawDecal(_DecalSprites->getMinX(), _DecalSprites->getMinY(),
				_DecalSprites->getMaxX(), _DecalSprites->getMaxY(), v, _FilterDistance);
		}
		glDisable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_CULL_FACE);
	}
	void DecalSystem::addDecal(float w, float h, unsigned char index, const Vector3D<float> &v)
	{
		_DecalList[_CurrentIndex] = Decal(w, h, _DefaultLife, index);
		_DecalList[_CurrentIndex++].setPosition(v);
	}
}